{% extends "base.html" %}
{% block title %}用户管理{% endblock %}
{% block head %}
    {{ super() }}

<script>
function initVM(data) {
	    vm = new Vue({
		el: '#form-user-add',
		data:{ 
			user:data,
			password:'',
			password1:'',
			password2:'',
		},
		methods: {
			submit: function (event) {
				event.preventDefault();
                if (! this.password.trim()) {
                    return alert('请输入旧密码');
                }
				old_password=CryptoJS.MD5(this.password).toString()
				if (old_password!=this.user.password) {
                    return alert('旧密码不正确');
                }
                if (this.password1.length < 6) {
                    return alert('口令长度至少为6个字符');
                }
                if (this.password1 !== this.password2) {
                    return alert('两次输入的口令不一致');
                }
				var $form = $('#form-user-add').find('form');
				postJSON('/api/password/modify',{
				user:this.user.id,
				password: CryptoJS.MD5(this.password1).toString(),
				}, function (err, r) {
					if (err) {
						showError(err);
					}
					else {
						return location.assign('/password');
					}
				});
			}
		}
	});
};

$(function () {
 	    getJSON('/api/password', function (err,results) {
            if (err) {
                return  (err);
            }
			initVM(results.user);
        });
    
})

 





</script>
{% endblock %}

{%block panel%}
<div class="tm-panel  uk-panel uk-panel-box  ">                        
	<div class="uk-panel-title">幼儿管理</div>
	<div class="uk-panel-li"><a href="/users">用户管理</a></div> 
	<div class="line"></div>
	<div class="uk-panel-li"><a href="/password">修改密码</a></div>
	<div class="line"></div>
	<div class="uk-panel-li"><a href="/config">基础设置</a></div> 
	<div class="line"></div>
</div>
{%endblock%}
					
{% block content %}
<div class="tit"><a href="/">主页 </a>  》 <a href="/">用户管理 </a></div>
<div class="divmain-title">幼儿入园登记</div>				




<div class="divmain" id="form-user-add" >
<form  v-on="submit: submit" class="uk-form uk-form-horizontal">

<div class="uk-form-row ">
	<label class="uk-form-label" for="name">旧口令:</label>
	<div class="uk-form-controls">
		<input v-model="password" id="password" type="password"  placeholder="旧口令" >
	</div>
</div> 	

<div class="uk-form-row ">
	<label class="uk-form-label">输入新口令:</label>
	<div class="uk-form-controls">
		<input v-model="password1" type="password" maxlength="50" placeholder="输入口令"> 
	</div>
</div>
<div class="uk-form-row ">
	<label class="uk-form-label">重复新口令:</label>
	<div class="uk-form-controls">
		<input v-model="password2" type="password" maxlength="50"  placeholder="重复口令">
	</div>
</div>

<div class="divbutton">
<button type="submit" class="uk-button uk-button-primary">修改</button>
</div>

</form>
</div>


</div>						
</li>
					
</ul>
{%endblock%}
             